﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TraCuuDiemNhom3.Commons;
using TraCuuDiemNhom3;
using System.Data;

namespace TraCuuDiemGroup3
{
    public partial class Login : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            TienIchWeb.XoaThongTinDangNhap();
            //kiem tra username va passowrd
            //


            TienIchWeb.GanTenDangNhap(txtUserName.Text);
            
            //string[] dsMaQuyen
            DataTable list_use = TienIchSQL.ChayLenhSelectDuLieu("select UserName, PassWord  from NguoiDung where UserName=@username AND PassWord=@MatKhau", "@username", txtUserName.Text, "@MatKhau", txtPass.Text);
            if (list_use.Rows.Count == 0)
            {
                lblThongBao.Text = "Dang nhap khong thanh cong";
            }
            else
            { 
                //Lay ds Quyen
                DataTable tbQuyen = TienIchSQL.ChayLenhSelectDuLieu("SELECT * FROM NguoiDung WHERE UserName=@username", "@username", txtUserName.Text);
                foreach (DataRow row in tbQuyen.Rows)
                    TienIchWeb.GanQuyen((string)row["Quyen"]);
               //  Test cho Xem Diem SV
              //  Response.Redirect(@"SinhVien/XemDiemSV.aspx");

                Response.Redirect("SuccessLogin.aspx");
            }
           // string[] dsMaQuyen = new string[] { "ad", "dt","ct","gv","sv" };            
        }

    }
}